package com.foldingleaf.web.controller.feedback;

import com.foldingleaf.common.annotation.Log;
import com.foldingleaf.common.core.controller.BaseController;
import com.foldingleaf.common.core.domain.Result;
import com.foldingleaf.common.core.page.TableDataInfo;
import com.foldingleaf.common.enums.BusinessType;
import com.foldingleaf.common.utils.poi.ExcelUtil;
import com.foldingleaf.feedback.domain.Feedback;
import com.foldingleaf.feedback.service.IFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 反馈Controller
 * 
 * @author ajian
 * @date 2022-06-10
 */
@Api(value = "/feedback/feedback", tags = {"反馈Controller"})
@RestController
@RequestMapping("/feedback/feedback")
public class FeedbackController extends BaseController
{
    @Autowired
    private IFeedbackService feedbackService;

    /**
     * 查询反馈列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Feedback", name = "feedback", value = "")
    })
    @ApiOperation(value = "查询反馈列表", notes = "查询反馈列表", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('feedback:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(Feedback feedback)
    {
        startPage();
        List<Feedback> list = feedbackService.selectFeedbackList(feedback);
        return getDataTable(list);
    }

    /**
     * 导出反馈列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "HttpServletResponse", name = "response", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "Feedback", name = "feedback", value = "")
    })
    @ApiOperation(value = "导出反馈列表", notes = "导出反馈列表", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('feedback:feedback:export')")
    @Log(title = "反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Feedback feedback)
    {
        List<Feedback> list = feedbackService.selectFeedbackList(feedback);
        ExcelUtil<Feedback> util = new ExcelUtil<Feedback>(Feedback.class);
        util.exportExcel(response, list, "反馈数据");
    }

    /**
     * 获取反馈详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "feedbackId", value = "")
    })
    @ApiOperation(value = "获取反馈详细信息", notes = "获取反馈详细信息", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('feedback:feedback:query')")
    @GetMapping(value = "/{feedbackId}")
    public Result getInfo(@PathVariable("feedbackId") Long feedbackId)
    {
        return Result.success(feedbackService.selectFeedbackByFeedbackId(feedbackId));
    }

    /**
     * 新增反馈
     */

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Feedback", name = "feedback", value = "")
    })
    @ApiOperation(value = "新增反馈", notes = "新增反馈", httpMethod = "POST")
    @Log(title = "反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Feedback feedback)
    {
        return toAjax(feedbackService.insertFeedback(feedback));
    }

    /**
     * 修改反馈
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Feedback", name = "feedback", value = "")
    })
    @ApiOperation(value = "修改反馈", notes = "修改反馈", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('feedback:feedback:edit')")
    @Log(title = "反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Feedback feedback)
    {
        return toAjax(feedbackService.updateFeedback(feedback));
    }

    /**
     * 删除反馈
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "Long[]", name = "feedbackIds", value = "")
    })
    @ApiOperation(value = "删除反馈", notes = "删除反馈", httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('feedback:feedback:remove')")
    @Log(title = "反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{feedbackIds}")
    public Result remove(@PathVariable Long[] feedbackIds)
    {
        return toAjax(feedbackService.deleteFeedbackByFeedbackIds(feedbackIds));
    }
}
